home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / open.c < prev    next >
Text File  |  1996-01-30  |  8KB  |  284 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* open.c */
  21.  
  22. #include "externs.h"
  23.  
  24.  
  25.  
  26.     
  27. void AVL_GET_FILE_NAMES(AVL_SOURCE_PTR s,char *pathn)
  28. {
  29.    struct find_t  c_file;
  30.    int n = 0;
  31.  
  32.    s -> no_files = 0;
  33.  
  34.    /* find first .ada file in current directory */
  35.    if (_dos_findfirst( pathn, _A_NORMAL, &c_file ))
  36.            return;    
  37.  
  38.    s -> no_files += 1;
  39.  
  40.    /* find the rest of the .ada files */
  41.    while( _dos_findnext( &c_file ) == 0 )
  42.         s -> no_files += 1;
  43.    if (_dos_findfirst( pathn , _A_NORMAL, &c_file ))
  44.            return;
  45.    sprintf(s -> name[n++],"%-12s",c_file.name);
  46.     
  47.    /* find the rest of the .ada files */
  48.    while( _dos_findnext( &c_file ) == 0 )
  49.            if (n >= AVL_TOOL_MAX)  {
  50.                AVL_ERROR("Too many sources scanned...");
  51.                break;
  52.                }
  53.            else
  54.             sprintf(s -> name[n++],"%-12s",c_file.name);
  55. }
  56.  
  57.  
  58.  
  59.  
  60. void AVL_SHOW_SOURCES(AVL_SOURCE_PTR w, int cols)
  61. {
  62.     short i, first, last, k;    
  63.     short co;
  64.     char msg[35];
  65.     char fmt[20];
  66.     sprintf(fmt," %cc %c-%ds", '%', '%', cols);
  67.     k = avl_cur_source / 15;
  68.     first = k * 15;
  69.     last = first + 14;
  70.     if (last >= avl_size) 
  71.         last = avl_size - 1;
  72.     _settextposition(1,1);
  73.     _outtext("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  74.     k = 1;
  75.     for(i = first; i <= last; ++i)  {
  76.         _settextposition(k,2);
  77.         if (i == avl_cur_source)
  78.             co = _settextcolor(avl_men_ready);
  79.         else
  80.             co = _settextcolor(avl_men_letter);
  81.         ++k;
  82.         _outtext(w -> name[i]);
  83.         }
  84.     _settextcolor(co);
  85. }
  86.                 
  87. int AVL_SOURCES(AVL_SOURCE_PTR w, int r, char *pathn)
  88. {
  89.         short x ;
  90.         short no = 0;
  91.         short ch, cols = 0, rows;
  92.         AVL_WIN_PTR hw, hw2;
  93.         if (r < 16)
  94.             rows = r;
  95.         else 
  96.             rows = 15;
  97.         avl_size = r;
  98.  
  99.         cols = 16;
  100.         hw2 = AVL_MAKE_WINDOW("",15,55,15+7,55+24,avl_wnd_bk_color,avl_wnd_color);
  101.         _outtext(" Use the arrow keys to\n");
  102.         _outtext(" go  over  the  files.\n");
  103.         _outtext("\n");
  104.         _outtext(" Press  <enter>  to\n");
  105.         _outtext(" select  a  file.\n");
  106.         _outtext(" Press ESC to  cancel.");
  107.         hw = AVL_MAKE_WINDOW(pathn,3,avl_menu[0].c,3+rows+1,avl_menu[0].c+cols+5,avl_wnd_bk_color,avl_wnd_color);
  108.  
  109.         while ( 1 )  {
  110.             AVL_SHOW_SOURCES(w,cols-4);
  111.             ch = getch();
  112.             if (ch == 13) {
  113.                 AVL_DEL_WINDOW(hw);
  114.                 AVL_DEL_WINDOW(hw2);
  115.                 return avl_cur_source;
  116.                 }
  117.             else {
  118.                 if (ch == 0 || ch == 0xE0) {
  119.                     ch = getch();
  120.                     switch( ch ) {
  121.                         case 73 : /* Page Up */ 
  122.                             avl_cur_source -= rows;
  123.                             if (avl_cur_source < 0)  
  124.                                 avl_cur_source = avl_size - 1;
  125.                             break;
  126.                         case 72 : /* Up */ 
  127.                             if (--avl_cur_source < 0)  
  128.                                 avl_cur_source = avl_size - 1;
  129.                             break;
  130.                         case 81 : /* Page Down */ 
  131.                             avl_cur_source += rows;
  132.                             if (avl_cur_source >= avl_size)
  133.                                 avl_cur_source = 0;
  134.                             break;
  135.                         case 80 : /* Down */ 
  136.                             if (++avl_cur_source >= avl_size)
  137.                                 avl_cur_source = 0;
  138.                             break;
  139.                         default : putchar(7); break;
  140.                         }
  141.                     continue;
  142.                     }
  143.                 if (ch == 27)  {
  144.                     AVL_DEL_WINDOW(hw);
  145.                     AVL_DEL_WINDOW(hw2);
  146.                     return -1;
  147.                     }
  148.                 putch(7);
  149.                 continue;
  150.                 }
  151.             }
  152. }            
  153.  
  154.  
  155.  
  156. void AVL_DO_LOAD()
  157. {
  158.     AVL_EDIT_WINDOW_PTR w;
  159.     AVL_WIN_PTR m;
  160.     AVL_SOURCE_SIZE t;
  161.     short n = 0, i=1000;
  162.     char s[161];
  163.     static int first = 0;
  164.     static char fname[161];
  165.     static char lastfn[121];
  166.     static char *msg = " GWAda - Open which file? ";
  167.     w = &avl_windows[avl_window];
  168.     m = AVL_MAKE_WINDOW(msg,7,4,9,5+62,avl_wnd_bk_color,avl_wnd_color);
  169.     if (first == 0)
  170.         sprintf(lastfn,"%s%c*.ada",avl_dir_sources,92);
  171.     first = 1;
  172.     strcpy(fname,lastfn);
  173.     if (AVL_PROMPT(1,1,fname,60)) {
  174.         AVL_DEL_WINDOW(m);
  175.         return;
  176.         }
  177.  
  178.     strcpy(lastfn,fname);
  179.     for(i = 0; i < strlen(fname); ++i)
  180.         if (fname[i] == '*' || fname[i] == '?')  {
  181.             i = -20;
  182.             break;
  183.             }
  184.     if (i > 0)
  185.         strcpy(w -> file_name, fname);
  186.     else {
  187.         AVL_GET_FILE_NAMES(&t,fname);
  188.         if (t.no_files == 0)  {
  189.             w -> file_name[0] = '\0';
  190.             sprintf(s,"Can't find any file under \'%s\'",fname);
  191.             AVL_ERROR(s);
  192.             }
  193.         else  {        
  194.             n = AVL_SOURCES(&t,t.no_files,fname);
  195.             if (n >= 0)  { 
  196.                 for(i = strlen(fname) - 1; t.no_files > 1 && i > 0; --i)  {
  197.                     if ((fname[i] == 92 || fname[i] == '\\') && i > 0) {
  198.                         fname[i+1] = '\0';
  199.                         i = -10;
  200.                         break;
  201.                         }
  202.                     }
  203.                 if (i < -1)
  204.                     sprintf(w -> file_name, "%s%s",fname,t.name[n]);
  205.                 else 
  206.                     sprintf(w -> file_name, "%s",t.name[n]);
  207.                 }
  208.             else 
  209.                 w -> file_name[0] = '\0';
  210.             }
  211.         }
  212.     AVL_DEL_WINDOW(m);
  213. }
  214.  
  215.                 
  216. void AVL_OPEN()
  217. {
  218.         AVL_LINE_PTR head = NULL, temp;
  219.         int x ;
  220.         int no = 0;
  221.         int ch, back;
  222.         char msg[80];
  223.         FILE *fp, *fopen();
  224.         AVL_WIN_PTR hw;
  225.         AVL_EDIT_WINDOW_PTR w;
  226.         if (avl_nwindows >= AVL_MAX_WINDOWS) {
  227.             sprintf(msg,"Can't open more than %d text files.", AVL_MAX_WINDOWS);
  228.             AVL_ERROR(msg);
  229.             return;
  230.             }
  231.         back = avl_window;
  232.         avl_window = avl_nwindows++;
  233.         w = &avl_windows[avl_window];
  234.         w -> head = w -> current_line = NULL;
  235.         AVL_DO_LOAD();
  236.         if (strlen(w -> file_name) == 0) {
  237.             --avl_nwindows;
  238.             avl_window = back;
  239.             return;
  240.             }
  241.         _settextrows( 25 );
  242.         _clearscreen( _GCLEARSCREEN );
  243.         AVL_LOAD_FILE(w -> file_name);
  244. }
  245.  
  246. void AVL_OPEN_ERROR()
  247. {
  248.         AVL_LINE_PTR head = NULL, temp;
  249.         int x ;
  250.         int no = 0;
  251.         int ch, back;
  252.         char *p, msg[80];
  253.         FILE *fp, *fopen();
  254.         AVL_WIN_PTR hw;
  255.         AVL_EDIT_WINDOW_PTR w;
  256.         if (avl_nwindows >= AVL_MAX_WINDOWS) {
  257.             sprintf(msg,"Can't open more than %d text files.", AVL_MAX_WINDOWS);
  258.             AVL_ERROR(msg);
  259.             return;
  260.             }
  261.         back = avl_window;
  262.         w = &avl_windows[avl_window];
  263.         for(x = strlen(current_file_name) - 1; current_file_name[x] != 92 && 
  264.             ¤t_file_name[x] != current_file_name; --x);
  265.         if (current_file_name[x] == 92) 
  266.             p = ¤t_file_name[x] + 1;
  267.         else 
  268.             p = ¤t_file_name;
  269.         for(x = 0; *(p+x) != '.' && *(p+x) != '\0'; ++x)
  270.             msg[x] = *(p+x);
  271.         msg[x] = '.';
  272.         msg[x+1] = 'l';
  273.         msg[x+2] = 'i';
  274.         msg[x+3] = 's';
  275.         msg[x+4] = '\0';
  276.         avl_window = avl_nwindows++;
  277.         w = &avl_windows[avl_window];
  278.         strcpy(w -> file_name,msg);
  279.         w -> head = w -> current_line = NULL;
  280.         _settextrows( 25 );
  281.         _clearscreen( _GCLEARSCREEN );
  282.         AVL_LOAD_FILE(w -> file_name);
  283. }
  284.